package com.qf.contorller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.qf.pojo.User;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * @author jiangjingbo
 * @version V1.0
 * @Project java2203
 * @Package com.qf.contorller
 * @Description:
 * @Date 2022/7/6 11:38
 */
@RestController
@RequestMapping("/search")
public class searchContorller {

    @RequestMapping("/test")
    public String test(){
//        int i =1/0;
        return "调用这个SearchContorller方法";
    }
    @RequestMapping("/findid/{id}")
    //指定兜底方法名 然后该方法出错那么就会执行兜底方法
    @HystrixCommand(fallbackMethod ="findByIdHystrix")
    public User findById(@PathVariable("id") Integer id){
        User user = new User();
        user.setId(id);
        int i =1/0;
        user.setName("饕鬄");
        user.setRiqi(new Date());
        return user;
    }
    //兜底方法
    public User findByIdHystrix(Integer id){
        User user = new User();
        user.setId(1);
        user.setName("hystrix熔断器拦截了");
        return user;
    }

    @RequestMapping("/user/{id}")
    public User test1(@PathVariable("id") Integer id){
        User user = new User();
        int i=1/0;
        user.setName("你好");
        return user;
    }
    @RequestMapping("/test2")
    @HystrixCommand(fallbackMethod = "Test2ee")
    public String Test2(){
        int i= 1/0;
       return "好累~~~~~";
    }

    public String Test2ee(){
        return "Hystrix熔断器拦截了";
    }
}
